/************************************************************************************************************
*	Modules
*	Author			Paul Kevin
*	Created:			12-Jan - 2009
*	Purpose of class:		Put modules
* 	Update log:			<log of change>
*
************************************************************************************************************/

/**
 * declare global variables
 */
var main;
var n = 1, myDiv, oInput;
var add = true;
var browser=navigator.appName;
var height;
var width;
var number;
var modules = new Array();



/**
 * Default constructor
 */
function main(){
}


main.prototype = {
	/*
	 * Global Variables
	 */
	 
	
	getAll : function(width,height, number, top_row){
		_main.setHeight(height);
		_main.setWidth(width);
		_main.setNumber(number);
		_main.readTextBox(number,width,height);
		
		var topR = Math.round((number/top_row),2);
		var h = Math.round(top_row/2);
		var leftCells = number % top_row;
		
		if((leftCells != 0) & (leftCells < h)){
			++topR;
		}
		
		var main = document.getElementById("main");
		var mH = ((10 + height) * (topR));
		var mW = ((10 + width) * top_row);
		main.style.height =  mH +"px";
		main.style.width = mW +"px";
		//main.style.background = "#CCCCCC";
		//main.style.border = "2px solid #000000";
	},
	
	/**
	 * Getters and setters
	 */
	getHeight: function(){
		return this.height;
	},
	
	
	setHeight : function(height){
		this.height = height;
	},
	
	getWidth : function(){
		return this.width;
	},
	
	setWidth : function(width){
		this.width = width;
	},
	
	getNumber : function(){
		return this.number;
	},
	
	setNumber : function(number){
		this.number = number;
	},
	
	setModules: function(modules){
        this.modules = modules;
    },
	
	getModules: function(){
        return this.modules;
    },


	

	/**
	 * Function to read from text box
	 */
	 readTextBox : function(oSelect,width,height){
	 //Variable to store data from user input
		var howmany = oSelect;
		
	      while (myDiv = document.getElementById('myDiv' + n))
	      if (n++ > howmany) {
			  add = false;
			  oForm.removeChild(myDiv);
	      }

	      if (add)
		  main = document.getElementById("main");

		  //main.style.visibility = "visible";
		  //main.style.position = "absolute";
		  //main.style.bottom="0";
	      for (n; n <= howmany; ++n) {
			  //Create div element inside main div
			  myDiv = document.createElement('div');
			  
			  //Set div attributes
			  myDiv.id = n;
				
			  myDiv.style.width = width +"px";
			  myDiv.style.minHeight= height +"px";
			  
			  //myDiv.style.background = "url(folder.png)";
			  //myDiv.style.border = "2px solid #000000";
			  myDiv.style.margin = "3px";
			  myDiv.style.visibility = "visible";
			  myDiv.style.position = "relative";
			  var jwt_modules = this.getModules();

			  var extUrl = "http://www.google.com";
			  var urlHead = "Google";
			  myDiv.innerHTML =  "<center><div style='width:"+width+";'><img src ='module/"+jwt_modules[n-1]+"/"+jwt_modules[n-1]+".png' style='cursor:pointer;' onclick='return GB_myShow(\""+urlHead+"\", \""+extUrl+"\")'/><div style='clear:both; float:none'>"+jwt_modules[n-1]+"</div></div></center>";
			  
			  if (browser == "Microsoft Internet Explorer") {
			  	myDiv.style.styleFloat = 'left';
			  	main.style.styleFloat = 'left';
			  }
			  else {
			  	myDiv.style.cssFloat = "left";
			  	main.style.cssFloat = "left";
			  }
			  
			  //Finally create div with all properties
			  main.appendChild(myDiv);
	      }
	}
}

//create new instance
var _main = new main();